<template>
  <view class="publish-management">
    <!-- 选项卡 -->
    <view class="tabs">
      <text
        :class="['tab', activeTab === 'all' ? 'active' : '']"
        @click="switchTab('all')"
      >
        全部
      </text>
      <text
        :class="['tab', activeTab === 'hiring' ? 'active' : '']"
        @click="switchTab('hiring')"
      >
        招聘中
      </text>
      <text
        :class="['tab', activeTab === 'review' ? 'active' : '']"
        @click="switchTab('review')"
      >
        审核状态
      </text>
      <text
        :class="['tab', activeTab === 'closed' ? 'active' : '']"
        @click="switchTab('closed')"
      >
        已关闭
      </text>
    </view>

    <!-- 职位信息列表 -->
    <view class="job-list">
      <!-- 全部 -->
      <view v-if="activeTab === 'all'" class="all-jobs">
        <view class="job-item" v-for="(job, index) in allJobs" :key="index">
          <text class="job-title">{{ job.title }}</text>
          <view class="job-content">
            <text class="job-details">{{ job.location }} | {{ job.education }} | {{ job.experience }} | {{ job.salary }} | {{ job.type }}</text>
            <text :class="['job-status', job.status === '在线中' ? 'online' : job.status === '审核中' ? 'review' : 'closed']">{{ job.status }}</text>
          </view>
        </view>
      </view>

      <!-- 招聘中 -->
      <view v-if="activeTab === 'hiring'" class="hiring-jobs">
        <view class="job-item" v-for="(job, index) in hiringJobs" :key="index">
          <text class="job-title">{{ job.title }}</text>
          <view class="job-content">
            <text class="job-details">{{ job.location }} | {{ job.education }} | {{ job.experience }} | {{ job.salary }} | {{ job.type }}</text>
            <text class="job-status online">{{ job.status }}</text>
          </view>
        </view>
      </view>

      <!-- 审核状态 -->
      <view v-if="activeTab === 'review'" class="review-jobs">
        <view class="job-item" v-for="(job, index) in reviewJobs" :key="index">
          <text class="job-title">{{ job.title }}</text>
          <view class="job-content">
            <text class="job-details">{{ job.location }} | {{ job.education }} | {{ job.experience }} | {{ job.salary }} | {{ job.type }}</text>
            <text class="job-status review">{{ job.status }}</text>
          </view>
        </view>
      </view>

      <!-- 已关闭 -->
      <view v-if="activeTab === 'closed'" class="closed-jobs">
        <view class="job-item" v-for="(job, index) in closedJobs" :key="index">
          <text class="job-title">{{ job.title }}</text>
          <view class="job-content">
            <text class="job-details">{{ job.location }} | {{ job.education }} | {{ job.experience }} | {{ job.salary }} | {{ job.type }}</text>
            <text class="job-status closed">{{ job.status }}</text>
          </view>
        </view>
      </view>
    </view>

    <!-- 发布新职位按钮 -->
    <view class="publish-button" @click="publishNewJob">
      <text>发布新职位</text>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      activeTab: "all", // 当前选中的选项卡
      allJobs: [
        {
          title: "网页设计",
          location: "佛山",
          education: "大专",
          experience: "3-5年",
          salary: "6-7K",
          type: "全职",
          status: "在线中",
        },
        {
          title: "网页设计",
          location: "佛山",
          education: "大专",
          experience: "3-5年",
          salary: "6-7K",
          type: "全职",
          status: "已关闭",
        },
        // 更多职位数据...
      ],
    };
  },
  computed: {
    hiringJobs() {
      return this.allJobs.filter(job => job.status === '在线中');
    },
    reviewJobs() {
      return this.allJobs.filter(job => job.status === '审核中');
    },
    closedJobs() {
      return this.allJobs.filter(job => job.status === '已关闭');
    },
  },
  methods: {
    // 切换选项卡
    switchTab(tab) {
      this.activeTab = tab;
    },
    // 发布新职位
    publishNewJob() {
      uni.navigateTo({ url: "/pages/form/post-recruit" });
    },
  },
};
</script>

<style scoped>
.publish-management {
  font-family: Arial, sans-serif;
  background-color: #fff;
  padding: 20px;
}

.tabs {
  display: flex;
  justify-content: space-around;
  margin-bottom: 20px;
  border-bottom: 1px solid #ebebeb;
}

.tab {
  padding: 10px;
  font-size: 16px;
  color: #666;
  cursor: pointer;
}

.tab.active {
  color: #007aff;
  border-bottom: 2px solid #007aff;
}

.job-list {
  margin-bottom: 80px; /* 为发布按钮留出空间 */
}

.job-item {
  background-color: #fff;
  padding: 15px;
  margin-bottom: 10px;
  border-bottom: 1px solid #ebebeb;
}

.job-title {
  font-size: 16px;
  font-weight: bold;
  color: #333;
  display: block;
  margin-bottom: 5px;
}

.job-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.job-details {
  font-size: 14px;
  color: #666;
  flex: 1;
  margin-right: 10px;
}

.job-status {
  font-size: 14px;
  font-weight: bold;
  white-space: nowrap;
}

.job-status.closed {
  color: #ff4d4f; /* 已关闭状态颜色 */
}

.job-status.online {
  color: #52c41a; /* 在线中状态颜色 */
}

.job-status.review {
  color: #faad14; /* 审核中状态颜色 */
}

.publish-button {
  background-color: #007aff;
  padding: 15px;
  border-radius: 8px;
  text-align: center;
  cursor: pointer;
  position: fixed;
  bottom: 20px;
  left: 20px;
  right: 20px;
}

.publish-button text {
  font-size: 16px;
  color: #fff;
}
</style>